# -*- coding: utf-8 -*-
from django.contrib import admin
from .models import Customer, Product, Order, Equipment, Employee, WorkOrder

@admin.register(Customer)
class CustomerAdmin(admin.ModelAdmin):
    list_display = ['name', 'code', 'contact', 'phone', 'created_at']
    list_filter = ['created_at']
    search_fields = ['name', 'code', 'contact']
    readonly_fields = ['created_at']

@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
    list_display = ['name', 'code', 'category', 'unit', 'price', 'created_at']
    list_filter = ['category', 'created_at']
    search_fields = ['name', 'code', 'category']
    readonly_fields = ['created_at']

@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
    list_display = ['order_no', 'customer', 'product', 'quantity', 'status', 'order_date']
    list_filter = ['status', 'order_date']
    search_fields = ['order_no', 'customer__name', 'product__name']
    readonly_fields = ['order_date']
    date_hierarchy = 'order_date'

@admin.register(Equipment)
class EquipmentAdmin(admin.ModelAdmin):
    list_display = ['name', 'code', 'model', 'location', 'status', 'last_maintenance']
    list_filter = ['status', 'location']
    search_fields = ['name', 'code', 'model']

@admin.register(Employee)
class EmployeeAdmin(admin.ModelAdmin):
    list_display = ['name', 'employee_id', 'department', 'position', 'is_active']
    list_filter = ['department', 'is_active', 'hire_date']
    search_fields = ['name', 'employee_id', 'position']

@admin.register(WorkOrder)
class WorkOrderAdmin(admin.ModelAdmin):
    list_display = ['work_order_no', 'order', 'assigned_to', 'equipment', 'status', 'created_at']
    list_filter = ['status', 'created_at']
    search_fields = ['work_order_no', 'order__order_no']
    readonly_fields = ['created_at']
    date_hierarchy = 'created_at' 